package com.example.dzcfinal.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.example.dzcfinal.InputActivity;
import com.example.dzcfinal.MainActivity;
import com.example.dzcfinal.NextActivity;
import com.example.dzcfinal.ProfileActivity;
import com.example.dzcfinal.R;


public class ProfileFragment extends Fragment {

    private Button profileBtn;
    private Integer userId;
    private Button myservice;
    private TextView textUserId;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_profile, container, false);

        textUserId = view.findViewById(R.id.textUserId);
        profileBtn = view.findViewById(R.id.profileBtn);
        userId = ((MainActivity)getActivity()).getUserId();
        myservice = view.findViewById(R.id.myservice);

        if (userId!=-1){
            textUserId.setText("个人中心");
        }


        myservice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(getActivity(), InputActivity.class);
                startActivity(intent);
            }
        });

        EnterProfileEdit();
        return view;
    }


    private void EnterProfileEdit(){
        profileBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (userId==-1){
                    Toast.makeText(getActivity(), "请登陆后再查看个人信息", Toast.LENGTH_SHORT).show();
                }else {
                    Intent intent =new Intent(getActivity(), ProfileActivity.class);
                    intent.putExtra("userId",userId);
                    startActivity(intent);
                }
            }
        });
    }

}